

//评论图片浏览器 通用--------start-----------

var _modelViewerCommon = $(".photoViewerCommon");
var currentDurl = '';
var currentArr = [];
$("#commentHtml").on('click','img',function () {
    var _this = $(this);
    currentDurl = _this.attr("src");
    currentArr[0] = currentDurl;
    $("#currentPic").attr('src',currentDurl);
    openViewCommon()

})

var photoViewCommon = new Swiper('.photoViewer-common',{
    spaceBetween: 20,
    observer:true,
    observeParents:true,
    lazyLoading : true,
    pagination : '.swiper-pagination',
    paginationType : 'fraction',
})


function openViewCommon(){
    _modelViewerCommon.show();
}
function closeViewCommon(){
    _modelViewerCommon.hide();
}
function showViewCommon(event){

    event.stopPropagation();
    var UIPhotoViewerCm = api.require('UIPhotoViewer');
    UIPhotoViewerCm.open({
        images: currentArr,
        activeIndex: 0,
        bgColor: '#000'
    }, function(ret, err) {
        if (ret) {
            if(ret.eventType =='click'){

                // var UIPhotoViewer = api.require('UIPhotoViewer');
                UIPhotoViewerCm.close();
            }
        } else {
        }
    });

}

function downloadPicCommon(event) {
    event.stopPropagation();
    var timestamp = new Date().getTime();
    var pathArr = currentDurl.split('.');
    var imgtypes = pathArr[pathArr.length - 1];
    api.download({
        url: currentDurl,
        savePath: 'fs://test'+timestamp+'.'+imgtypes,
        report: true,
        cache: true,
        allowResume: true,
        networkTypes:"all"
    }, function(ret, err) {
        console.log(JSON.stringify(ret))
        if(ret.state==1){
            api.saveMediaToAlbum({
                path: ret.savePath
            }, function(res, errs) {
                console.log(JSON.stringify(res))
                console.log(JSON.stringify(errs))
                if(res.status ==true){
                    api.toast({
                        msg:'图片已保存到相册'
                    })
                }else{
                    api.toast({
                        msg:'图片保存到相册失败'
                    })
                }
            });
        }

    });

}

//评论图片浏览器 通用--------end-----------